<template>
  <div class="welcome-container" @mousemove="handleMouseMove">
    <div class="particles-container"></div>
    <div class="glass-overlay"></div>
    <div class="welcome-content" :style="contentStyle">
      <div class="logo-container">
        <div class="logo-wrapper">
          <img src="@/assets/logo-1.jpg" alt="logo" class="logo">
          <div class="logo-glow"></div>
        </div>
      </div>
      <h1 class="glowing-text" :style="titleStyle">欢迎使用中药材电商后台管理系统</h1>
      <p class="subtitle" :style="subtitleStyle">选择左侧菜单开始您的操作</p>
      <div class="decoration-line">
        <div class="line-glow"></div>
      </div>
      <div class="floating-elements">
        <div class="floating-circle" :style="elementStyles.circle"></div>
        <div class="floating-square" :style="elementStyles.square"></div>
        <div class="floating-triangle" :style="elementStyles.triangle"></div>
      </div>
      <div class="interactive-background">
        <div class="gradient-sphere"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, ref, reactive } from 'vue';

const mousePos = reactive({ x: 0, y: 0 });
const contentStyle = ref({});
const titleStyle = ref({});
const subtitleStyle = ref({});
const elementStyles = reactive({
  circle: {},
  square: {},
  triangle: {}
});

const handleMouseMove = (e) => {
  const { clientX, clientY } = e;
  const centerX = window.innerWidth / 2;
  const centerY = window.innerHeight / 2;

  mousePos.x = (clientX - centerX) / centerX;
  mousePos.y = (clientY - centerY) / centerY;

  updateStyles();
};

const updateStyles = () => {
  const intensity = 15;
  const rotateX = mousePos.y * intensity;
  const rotateY = mousePos.x * intensity;

  contentStyle.value = {
    transform: `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`
  };

  titleStyle.value = {
    transform: `translateZ(50px) rotateX(${-rotateX * 0.5}deg) rotateY(${-rotateY * 0.5}deg)`
  };

  subtitleStyle.value = {
    transform: `translateZ(30px) rotateX(${-rotateX * 0.3}deg) rotateY(${-rotateY * 0.3}deg)`
  };

  elementStyles.circle = {
    transform: `translate3d(${mousePos.x * 20}px, ${mousePos.y * 20}px, 50px)`
  };
  elementStyles.square = {
    transform: `translate3d(${-mousePos.x * 30}px, ${-mousePos.y * 30}px, 30px) rotate(${mousePos.x * 45}deg)`
  };
  elementStyles.triangle = {
    transform: `translate3d(${mousePos.x * 25}px, ${mousePos.y * 25}px, 40px) rotate(${-mousePos.y * 45}deg)`
  };
};

onMounted(() => {
  initParticles();
});

onUnmounted(() => {
  const container = document.querySelector('.particles-container');
  if (container) {
    container.innerHTML = '';
  }
});

function initParticles() {
  const container = document.querySelector('.particles-container');
  for (let i = 0; i < 50; i++) {
    const particle = document.createElement('div');
    particle.className = 'particle';
    particle.style.left = `${Math.random() * 100}%`;
    particle.style.top = `${Math.random() * 100}%`;
    particle.style.animationDelay = `${Math.random() * 5}s`;
    container.appendChild(particle);
  }
}
</script>

<style scoped>
.welcome-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background: linear-gradient(135deg, #0a0f16 0%, #1a2431 100%);
  overflow: hidden;
  position: relative;
  perspective: 2000px;
}

.welcome-content {
  text-align: center;
  padding: 3rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 30px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(30px);
  transform-style: preserve-3d;
  transform: translateY(20px);
  opacity: 0;
  animation: slideUp 1s cubic-bezier(0.23, 1, 0.32, 1) forwards;
  position: relative;
  max-width: 90%;
  width: 700px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 30px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.1), transparent);
    z-index: -1;
  }

  &:hover {
    transform: translateY(0);
    box-shadow: 0 35px 70px rgba(0, 0, 0, 0.4);
  }
}

.logo-container {
  margin-bottom: 2rem;
  perspective: 1000px;
}

.logo-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto;
  transform-style: preserve-3d;
  animation: float 6s ease-in-out infinite;

  &::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
    filter: blur(15px);
    z-index: -1;
  }
}

.logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
  transition: transform 0.3s ease;

  &:hover {
    transform: scale(1.1) rotate(5deg);
  }
}

.glowing-text {
  color: #ffffff;
  margin-bottom: 2rem;
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.3;
  background: linear-gradient(45deg, #ffffff, #7eb6ff, #5e9eff);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(126, 182, 255, 0.6);
  animation: glow 2s ease-in-out infinite alternate,
    gradientMove 8s ease infinite;
  transform-style: preserve-3d;
}

.subtitle {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.5rem;
  line-height: 1.6;
  margin-bottom: 2.5rem;
  font-weight: 300;
  letter-spacing: 1.5px;
  transform-style: preserve-3d;
  transition: all 0.4s ease;

  &:hover {
    color: #ffffff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
  }
}

.decoration-line {
  width: 150px;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  border-radius: 2px;

  .line-glow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
    animation: shimmer 3s ease-in-out infinite;
    filter: blur(2px);
  }
}

@keyframes slideUp {
  from {
    transform: translateY(40px) rotateX(10deg);
    opacity: 0;
  }

  to {
    transform: translateY(0) rotateX(5deg);
    opacity: 1;
  }
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-20px) rotate(5deg);
  }
}

@keyframes glow {
  from {
    text-shadow: 0 0 10px rgba(126, 182, 255, 0.5),
      0 0 20px rgba(126, 182, 255, 0.3);
  }

  to {
    text-shadow: 0 0 30px rgba(126, 182, 255, 0.8),
      0 0 50px rgba(126, 182, 255, 0.5);
  }
}

@keyframes gradientMove {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(200%);
  }
}

@media (max-width: 768px) {
  .welcome-content {
    padding: 2rem;
    transform: translateY(10px) rotateX(2deg);
  }

  .glowing-text {
    font-size: 1.8rem;
  }

  .subtitle {
    font-size: 1.1rem;
  }

  .logo-wrapper {
    width: 80px;
    height: 80px;
  }
}

.particles-container {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: moveParticle 15s linear infinite;
  filter: blur(1px);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.floating-elements {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: -1;
  transform-style: preserve-3d;
}

.floating-circle,
.floating-square,
.floating-triangle {
  position: absolute;
  opacity: 0.15;
  animation: floatElement 10s ease-in-out infinite;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
  filter: blur(1px);
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
}

.floating-circle {
  width: 50px;
  height: 50px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  top: 20%;
  left: 10%;
}

.floating-square {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  bottom: 20%;
  right: 10%;
  animation-delay: -5s;
}

.floating-triangle {
  width: 0;
  height: 0;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  border-bottom: 40px solid rgba(255, 255, 255, 0.3);
  top: 40%;
  right: 20%;
  animation-delay: -2.5s;
}

@keyframes moveParticle {
  0% {
    transform: translateY(0) translateX(0);
    opacity: 0;
  }

  50% {
    opacity: 1;
  }

  100% {
    transform: translateY(-100vh) translateX(100vw);
    opacity: 0;
  }
}

@keyframes floatElement {

  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }

  50% {
    transform: translate(20px, -20px) rotate(180deg);
  }
}
</style>